package com.swpu.service_archive.controller;


import com.swpu.commonutils.JwtUtils;
import com.swpu.commonutils.R;
import com.swpu.commonutils.ResultEncryption;
import com.swpu.service_archive.entity.ArchiveBasic;
import com.swpu.service_archive.service.ArchiveBasicService;
import com.swpu.service_user.aop.Decrypt;
import com.swpu.service_user.aop.Encrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chaichai
 * @since 2024-04-12
 */
@RestController
@RequestMapping("/service_archive/archive-basic")
public class ArchiveBasicController {
    @Autowired
    private ArchiveBasicService archiveBasicService;
    @PostMapping("addArchiveBasic")
    @Decrypt
    @Encrypt
    public R addArchiveBasic(@RequestBody ResultEncryption resultEncryption, ArchiveBasic archiveBasic, HttpServletRequest request){
        String openid = JwtUtils.getOpenidByJwtToken(request);
        if (openid.isEmpty()){
            return R.error().message("用户未登录");
        }
        archiveBasicService.addArchiveBasic(openid,archiveBasic);
        return  R.ok();
    }

    @GetMapping("getArchiveBasic")
    public R getArchiveBasic(HttpServletRequest request){
        String openid = JwtUtils.getOpenidByJwtToken(request);
        if (openid.isEmpty()){
            return R.error().message("用户未登录");
        }
        ArchiveBasic archiveBasic = archiveBasicService.getArchiveBasic(openid);
        return  R.ok().data("archiveBasic",archiveBasic);
    }

}

